package com.example.demo.Util;

import java.io.*;

public class FileUtil {

    public static boolean writeFile(String path,String content) {
       try {
           File file=new File(path);
           OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file));
           out.write(content);
           out.flush();
           out.close();
           return true;
       }catch (Exception e)
       {
           e.printStackTrace();
           return false;
       }
    }

    public static String readFile(String path) {
        BufferedReader br = null;
        String str = "";
        try {
            br = new BufferedReader(new InputStreamReader(new FileInputStream(path)));
            String data = null;
            while ((data = br.readLine()) != null) {
                str += data;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            return str;
        }
    }
    public static void main(String args[])
    {
        FileUtil.writeFile("D:\\1.text","哈哈哈");
       String str= FileUtil.readFile("D:\\1.text");
       System.out.println(str);
    }
}
